package com.imooc.ad.common;

import com.imooc.ad.constant.ResponseCode;
import lombok.Data;

/**
 * Created by lzq on 2019/3/6
 */
@Data
public class Result<T> {

    private int code;
    private String msg;
    private T result;

    public static <T> Result<T> success(){
        return new Result<T>();
    }

    public static <T> Result<T> success(T result){
        Result response = new Result<T>();
        response.setResult(result);
        return response;
    }

    public static <T> Result<T> error(ResponseCode code){
        return new Result<T>(code.code,code.msg);
    }

    public Result(){
        this(ResponseCode.SUCCESS.code,ResponseCode.SUCCESS.msg);
    }

    public Result(int code,String msg){
        this.code = code;
        this.msg = msg;
    }

}
